package com.nenude.corejava.ch6.game;

import java.nio.channels.ShutdownChannelGroupException;

import javax.swing.text.StyledEditorKit.ForegroundAction;

import com.nenude.corejava.ch6.Outter.Inner.inner2;

//类指的是类型，是由多个具有相同特征的事务(对象)，抽象出来的；

public class People {
	// 名字
	private String name;
	// 武器
	private String weapon;
	// 战斗力
	private int attack;
	// 耐力
	private int endurance;

	// 事例：
	public static void main(String[] args) {
		// 类与对象的关系
		// 对象抽象出类，类实例化为对象

		People sun = new People("孙悟空", "金箍棒", 5, 5);
		sun.fighting();
		sun.defense();

		People sun2 = new People("孙悟空2", "金箍棒", 5, 5);
		sun2.fighting();
		sun2.defense();

		People tang = new People("唐僧", "无", 0, 5);
		tang.fighting();
		tang.defense();

		People zhu = new People("猪八戒", "耙子", 4, 2);
		zhu.fighting();
		zhu.defense();

		People sha = new People("沙僧", "月牙铲", 3, 4);
		sha.fighting();
		sha.defense();
		
		
		//垃圾回收机制的实例
		People people=null;
		for(int i=0;i<1000000000;i++){
			//在循环外，超出生命周期的对象都是垃圾
			 people=new People();
		}
		System.gc();//通知垃圾会回收期；jvm 收到通知后，会调度gc进行内存回收。
		//内部才能泄漏：当有一个堆内存一直有栈指针指向他，这块堆内存则无法进行回收；这种情况称为内存泄漏；
			
		
		//修改文件1234
		
	}
	

	// 一个类编写了带参构造方法后，会屏蔽默认的空参构造方法
	// 如果需要使用空参构造方法，必须显示编写一个
	public People() {
		super();
		// TODO Auto-generated constructor stub
	}

	public People(String name, String weapon, int attack, int endurance) {
		super();
		this.name = name;
		this.weapon = weapon;
		this.attack = attack;
		this.endurance = endurance;
	}

	// getter 和 setter 方法
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getWeapon() {
		return weapon;
	}

	public void setWeapon(String weapon) {
		this.weapon = weapon;
	}

	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}

	public int getEndurance() {
		return endurance;
	}

	public void setEndurance(int endurance) {
		this.endurance = endurance;
	}

	// 战斗
	public void fighting() {
		System.out.println(name + "在战斗  " + weapon + "是武器");
	}

	// 防御
	public void defense() {
		System.out.println(name + "在防御    " + weapon + "是武器");
	}

}
